Redis cluster实现master水平扩容
1 | 192.168.31.231 matrix-cache01 |
1 | redis cluster模式下,不建议做物理的读写分离了 |
redis扩容
加入新master
1 | [root@matrix-cache03 ~]# mkdir -p /var/redis/7007 |
1 | [root@matrix-cache03 ~]# cd /etc/redis |
1 | [root@matrix-cache03 redis]# vi 7007.conf |
1 | port 7007 |

1 | [root@matrix-cache03 ~]# cd /etc/init.d |
1 | [root@matrix-cache03 init.d]# vi redis_7007 |

启动新master
1 | [root@matrix-cache03 init.d]# ./redis_7007 start |

在集群中加入新master
1 | [root@matrix-cache01 ~]# cd /usr/local |

1 | [root@matrix-cache01 local]# redis-trib.rb check 192.168.31.231:7001 |

1 | 连接到新的redis实例上,cluster nodes,确认自己是否加入了集群,作为了一个新的master |
1 | [root@matrix-cache03 ~]# redis-cli -h 192.168.31.233 -p 7007 |
reshard一些数据过去
1 | resharding的意思就是把一部分hash slot从一些node上迁移到另外一些node上 |
1 | 要把之前3个master上,总共4096个hashslot迁移到新的第四个master上去 |
1 | [root@matrix-cache01 local]# redis-trib.rb reshard 192.168.31.231:7001 |


1 | 输入完ID后 |
查看7007是否分配到了数据
1 | [root@matrix-cache01 local]# redis-trib.rb check 192.168.31.231:7001 |

添加node作为slave
1 | [root@matrix-cache03 ~]# mkdir -p /var/redis/7008 |
1 | [root@matrix-cache03 ~]# cd /etc/redis |
1 | port 7008 |

1 | [root@matrix-cache03 ~]# cd /etc/init.d |
1 | [root@matrix-cache03 init.d]# vi redis_7008 |

1 | [root@matrix-cache03 init.d]# ./redis_7008 start |

1 | [root@matrix-cache01 local]# redis-trib.rb add-node --slave --master-id e2498a3792ee21cd70736fead0d7f3157ded2f0d 192.168.31.233:7008 192.168.31.231:7001 |


删除node
1 | 先用resharding将数据都移除到其他节点,确保node为空之后,才能执行remove操作 |
1 | [root@matrix-cache01 local]# redis-trib.rb reshard 192.168.31.231:7001 |


1 | 将7007的4096 slots数据移动到别的节点 |
1 | [root@matrix-cache01 local]# redis-trib.rb del-node 192.168.31.231:7001 e2498a3792ee21cd70736fead0d7f3157ded2f0d |

1 | [root@matrix-cache01 local]# redis-trib.rb check 192.168.31.231:7001 |

本文作者 : Matrix
原文链接 : https://matrixsparse.github.io/2017/06/28/Redis cluster实现master水平扩容/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
知识 & 情怀 | 二者兼得